package com.example.demo.controller;

import com.example.demo.controller.viewObject.UserVO;
import com.example.demo.response.CommonResuletType;
import com.example.demo.service.UserService;
import com.example.demo.service.module.UserModule;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller("user")
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @ResponseBody
    @RequestMapping("/get")
    public CommonResuletType getUser(@RequestParam (name = "id") Integer id){
        UserModule userModule =userService.getUserById(id);
        UserVO userVO= convertFromMoudle(userModule);
        return CommonResuletType.craete(userVO);
    }

    private UserVO convertFromMoudle(UserModule userModule){
        UserVO userVO=new UserVO();
        BeanUtils.copyProperties(userModule,userVO);
        return userVO;
    }
}
